<?php


$num_arr=range(1,10);
#PHP这里range函数是1-10,包括10,
#而python里的range函数不包括10
print_r($num_arr);
$num_arr=range(1,10,2);
#第三个参数是步长,和python一样
print_r($num_arr);
$num_arr[2]="中国";
print_r($num_arr);

$len=count($num_arr);
for ($i = 0; $i < $len; $i++) {
    echo $num_arr[$i]." ";
}
unset($i);
echo "\n";

foreach ($num_arr as $k=>&$v){
    #&$v表示引用不复制
    echo $v." ";
    $v=$v."1";
    
}
unset($v);
#unset($v)这个引用放在污染数组(即防治后面修改)

print_r($num_arr);

foreach ($num_arr as $k=>$v){
    #&$v表示引用不复制
    echo $v." ";
    $v=$v."2";
    
}
print_r($num_arr);

$array=[
    [9,2],
    [3,4],
];
foreach ($array as list($a,$b)){
    #list可以减少一层包裹,但理论上增加了性能消耗
    echo " $a  "."$b \n";
}
$info =array("啡"=>25,"水"=>23,"牛"=>22);

list($a,$b,$c)=$info;
echo"---------------\n";
var_dump($a, $b,$c);
#将会打印NULL,NULL,NULL,
#list函数只能获取数字下标
echo"---------------\n";


$var_array = array("color" => "blue",
    "size"  => "medium",
    "shapet" => "sphere",
    "shapew" => "sphere",
    "shapek" => "sphere",
    
);

$var_array=array_unique($var_array);
#array_unique函数移除重复的值,期望在返回值,期望值不再本体
#总之,array_unique函数去重复
# 用于去除重复是数字
print_r($var_array);


$blist=array(
    "ll"=>12,
    "jj"=>16,
    "oo"=>14,
    
);
$blist=array_flip($blist);
#array_flip函数,键值对互换
print_r($blist);
$blist=array_flip($blist);
print_r($blist);
//phpinfo();
// 获取加载的扩展
$extensions = get_loaded_extensions();

// 打印加载的扩展数量
echo "加载的扩展数量: " . count($extensions) . "\n";

// 遍历并打印所有加载的扩展
foreach ($extensions as $ext) {
    echo $ext . "\n";
}
$userA=array("dd"=>"李丽");
array_unshift($userA,"误伤");
print_r($userA);
array_shift($userA);
print_r($userA);

$userB=array("aa"=>"王丽","cc"=>"周琦");

array_push($userB,['ff'=>"吴奇隆"]);
array_push($userB,"孙传芳");
print_r($userB);
array_pop($userB);
print_r($userB);


$products=array("orange","banner","apple");
print_r(array_rand($products,2));




$userC=array("aa"=>"王丽","cc"=>"周琦",
    'ff'=>"",
    'zz'=>"诸葛亮",
    'zf'=>"张飞",
    'sx'=>"孙权",
    'dd'=>"曹操",
    
);
echo current($userC);
#current获取当前元素,数组指针不下移动
echo current($userC);
echo current($userC);
echo current($userC);

echo next($userC);
#获取当前元素,并下移指针
echo current($userC)." \n";

echo reset($userC);
#reset 重置指针
echo current($userC)." \n";
next($userC);
 
 echo"------";
 echo current($userC)." \n";
echo prev($userC);

#prev函数返回当前元素,然后把指针回一位,
//echo current($userC)." \n";

echo count($userC)." ";
echo sizeof($userC);

#函数sizeof统计数组元素个数
#count函数统计数组个数

$array=array(1,2,4,3,1,5,2,6,7,2);
print_r(array_count_values($array));
#array_count_values函数统计数组元素出现的次数


$array=array(
    'k1'=>'apple',
    "k2"=>"banner",
    "k3"=>"orange",
    "green",
    "k4"=>"red"
);

extract($array);
#extract函数把数组元素变成当前变量,只支持非数字元素
echo " : ".$k1;
echo " : ".$k2;
echo " : ".$k3;
echo " : ".$k4;



